package com.monliao.thread.util;

import org.htmlparser.Parser;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.nodes.TagNode;
import org.htmlparser.util.NodeList;

public class threadTest extends Thread {
	
				
		public static void main(String[] args) {
			
				try {
					
					
					Parser parser=new Parser("http://mm.10086.cn/android/software/qbrj");
					parser.setEncoding("UTF-8");
					HasAttributeFilter attributeFilter=new HasAttributeFilter("class","last");
					
					
					NodeList nodeList = parser.parse(attributeFilter);
					
					System.out.println();
				
					//总抓取量
					int totalNum=Integer.parseInt(((TagNode)nodeList.elementAt(0)).getAttribute("href").split("=")[1]);
					//每个线程的量
					int threadOneNum=10;
					//计算线程量
					int threadNum=totalNum/threadOneNum+(threadOneNum%totalNum==0?0:1);
					
				for (int i = 0; i < threadNum; i++) {
					
					runThread thread =new runThread(threadOneNum*i+1,threadOneNum*(i+1)>totalNum?totalNum:threadOneNum*(i+1));
					thread.start();
				}
				
				
				
				
				
				
				
				
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
}
